home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / amos / amoslist-0295.lzh / AMOSLIST / text0017.txt < prev    next >
Encoding:
Text File  |  1995-03-01  |  1.5 KB  |  44 lines

  1. >> BTW, why would you want to use recursion for this Mines-clone. You 
  2. >> could just check the array, could you not?
  3. >No, because I have to know which clear squares connect to which. I mean, 
  4. >what do you exactly mean with checking the array. AFAIK checking the 
  5. >array implies resorting to some form of recursive programming.
  6. >(I learned that term from someone who sent me an example once of the 
  7. >core of minesweeper, and he spoke of recursive programming.)
  8. >
  9. >So, could anyone post me something similar?
  10.  
  11.   The core of the "step" routine would look something like this:
  12.  
  13. Procedure _STEP[X,Y]
  14.    'W and H are the width and height of the board
  15.    Shared W,H
  16.  
  17.    If BOARD(X,Y)=-1
  18.       'Oops, he stepped on a mine
  19.    Else If BOARD(X,Y)>0
  20.       'Display the count of surrounding mines
  21.       DISP_COUNT[X,Y]
  22.    Else
  23.       'Square is clear, display it and step on surrounding squares
  24.       DISP_CLEAR[X,Y]
  25.       'Loop through surrounding squares.  Min() and Max() make sure we
  26.       'don't go off the edge.
  27.       For Y2=Max(0,Y-1) To Min(H-1,Y+1)
  28.          For X2=Max(0,X-1) To Min(W-1,X+1)
  29.             If X2<>X or Y2<>Y
  30.                'Call _STEP recursively to step on the surrounding squares.
  31.                _STEP[X2,Y2]
  32.             End If
  33.          Next X2
  34.       Next Y2
  35.    End If
  36. End Proc
  37.  
  38.   Anybody get the idea I've written one too? :)  For that matter, I even
  39. did a 3-D one, if anyone's interested.
  40.  
  41.   --Andy Church (achurch@goober.mbhs.edu)
  42.     WWW: http://www.mbhs.edu/~achurch/
  43.  
  44.